package delyqueue;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author chaird
 * @create 2023-04-16 17:18
 */
public class APP {

  public static void main(String[] args) throws Exception{
    ExecutorService executor = Executors.newFixedThreadPool(2);

    DelayQueue<DelayedUser> queue = new DelayQueue<>();
    int messageCount = 2;
    long delayTime = 500;
    DelayedQueueConsumer consumer = new DelayedQueueConsumer(
            queue, messageCount);
    DelayedQueueProducer producer = new DelayedQueueProducer(
            queue, messageCount, delayTime);

    // when
    executor.submit(producer);
    executor.submit(consumer);

    // then
    executor.awaitTermination(5, TimeUnit.SECONDS);
    executor.shutdown();
  }
}
